package com.wiz.weixin.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wiz.weixin.common.Constant;
import com.wiz.weixin.manager.HttpManager;
import com.wiz.weixin.service.ScanRefuelingService;
import com.wiz.weixin.vo.AuthVO;
import com.wiz.weixin.vo.ResultVO;

/**
 * 扫一扫 加油服务
 * @author xxy
 */
@Service("scanRefuelingService")
public class ScanRefuelingServiceImpl implements ScanRefuelingService {
	private transient final Logger log = LoggerFactory.getLogger(getClass());
	
	@Resource
	private Gson gson;
	@Resource
	private HttpManager httpManager;

	@Override
	public ResultVO authorization(AuthVO authVO) throws Exception {
		List<NameValuePair> formparams = new ArrayList<NameValuePair>();
		String params = gson.toJson(authVO);
	    formparams.add(new BasicNameValuePair("params", params));
	    log.info("call center="+params);
		// 调用接口
		String response = httpManager.getResponseByHttpPost(Constant.AUTH_URL,formparams);
//	    Thread.sleep(40000);
//	    String response = ResponseCode.DATA_OK;
		log.info("scanRefueling from DataCenter:"+response+"    params="+params);
		return gson.fromJson(response, new TypeToken<ResultVO>(){}.getType());
	}

}
